package com.xunge.controller;

import com.xunge.anno.Log;
import com.xunge.pojo.*;
import com.xunge.service.ClazzService;
import com.xunge.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    /*
        班级分页查询
     */
    @GetMapping
    public Result pageClazz(ClazzQueryParam clazzQueryParam){
        log.info("班级管理分页请求参数:{}" ,clazzQueryParam);
        PageResult<Clazz> pageResult = clazzService.page(clazzQueryParam);
        return Result.success(pageResult);
    }
    /*
    * 添加班级
    */
    @Log
    @PostMapping
    public Result addClazz(@RequestBody Clazz clazz){
        log.info("添加班级请求参数:{}" ,clazz);
        clazzService.save(clazz);
        return Result.success();
    }
    //根据id查询班级信息
    //查询回显
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("根据ID查询班级信息: {}",id);
        Clazz clazz = clazzService.getById(id);
        return Result.success(clazz);
    }
    @Log
    //修改班级信息
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级信息: {}",clazz);
        clazzService.update(clazz);
        return Result.success();
    }
    @Log
    //根据id删除班级信息
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据ID删除班级信息: {}",id);
        clazzService.delete(id);
        return Result.success();
    }
    @GetMapping("/list")
    public Result findAll(){
        log.info("查询班级所有信息");
        List<Clazz> clazzAll = clazzService.findAll();
        return Result.success(clazzAll);
    }
}
